package com.fs.video.cotroller;

import com.fs.video.common.utils.SukeJSONResult;
import com.fs.video.service.UsersService;
import com.fs.video.vo.UsersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
/**
 * 处理用户的增删改查操作
 */
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private UsersService usersService;

    @RequestMapping("/queryById")
    public SukeJSONResult queryById(String userId){
        //userId的非空验证
        if(userId == null || userId.isEmpty()){
            return SukeJSONResult.errorMsg("用户id不能为空");
        }
        //调用业务层查询
        UsersVO usersVO = usersService.queryById(userId);
        usersVO.setToken("");
        return SukeJSONResult.ok(usersVO);
    }

    /**
     * 用户上传头像
     *
     * MultipartFile:接收上传的文件
     */
    @PostMapping("/uploadFace")
    public SukeJSONResult uploadFace(String userId, MultipartFile photo){
        //userId的非空验证
        if(userId == null || userId.isEmpty()){
            return SukeJSONResult.errorMsg("用户id不能为空");
        }
        //调用业务层保存文件并修改users表, 把上传文件的路径保存到对应的用户的face_image
        String faceImage = usersService.uploadFace(userId, photo);
        return SukeJSONResult.ok(faceImage);

    }

}
